package com.ess.result;

/**
 * <p/>
 * Description:
 * <p/>
 * REST接口返回的结果状态码,这些结果状态码参照HTTP协议
 */
public enum ResultCode {


    C401(401, "No Login"),
    C403(403, "Forbidden"),
    C404(404, "Not Found"),
    C406(406, "Parameters Error"),
    C500(500, "Internal Server Error"),

    SYSTEM_SUCCESS_CODE(200, "操作成功"),
    SYSTEM_FAILURE_CODE(199999, "系统异常"),
    SYSTEM_MESSAGE_CODE(200000, "重复操作"),
    SYSTEM_CODE_DUPLICATE(200001, "系统编码重复"),
    SYSTEM_NAME_DUPLICATE(200002, "该名称已存在"),
    SYSTEM_CONNECTION_ERROR(200003, "网络连接异常,请稍后重试!"),
    /**
     * 200004, "请求参数错误"
     */
    SYSTEM_PARAMETER_ERROR(200004, "请求参数错误"),
    SYSTEM_MENU_PARENT_SID_NO_REQUIRED(200005, "顶级菜单没有上一级菜单"),
    SYSTEM_MENU_PARENT_SID_REQUIRED(200006, "非顶级菜单上一级菜单不可空"),
    SYSTEM_USER_DUPLICATE(200007, "用户名已存在"),
    SYSTEM_USER_ROLE_DUPLICATE(200008, "用户角色有关系已存在"),
    SYSTEM_ROLE_DUPLICATE(200009, "角色名已存在"),
    SYSTEM_USER_NO_LOGIN(200010, "用户未登录");


    public int code;//code
    public String desc;//description

    ResultCode(int code, String desc) {
        this.code = code;
        this.desc = desc;
    }

    public static ResultCode format(String name) {
        for (ResultCode value : ResultCode.values()) {
            if (name.equals(value.toString())) {
                return value;
            }
        }
        return null;

    }

    public static ResultCode formatName(int valKey) {
        for (ResultCode value : ResultCode.values()) {
            if (valKey == value.getCode()) {
                return value;
            }
        }
        return null;
    }

    public int getCode() {
        return code;
    }

    public String getDesc() {
        return desc;
    }
}
